package com.atguigu.cloud.service.Impl;

import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.mapper.PayMapper;
import com.atguigu.cloud.service.PayService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:PayServiceImpl
 * Package:com.atguigu.cloud.service.Impl
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/6/3 - 21:57
 * @Version:v1.0
 */
@Service
public class PayServiceImpl implements PayService {

    @Resource
    private PayMapper payMapper;
    @Override
    public int add(Pay pay) {
        //payMapper.insert(pay);//保存一个实体，null的属性也会保存，不会使用数据库默认值
        return payMapper.insertSelective(pay);//保存一个实体，null的属性不会保存，会使用数据库默认值
    }

    @Override
    public int delete(Integer id) {
        //按照主键删除
        return payMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(Pay pay) {

        //根据主键更实体中属性不为null的值，null的属性会自动使用数据库的默认值
        return payMapper.updateByPrimaryKeySelective(pay);
    }

    @Override
    public Pay getById(Integer id) {
        //根据id查找
        return payMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Pay> getAll() {
        return payMapper.selectAll();
    }
}
